
function evolve:tables_exist()
 
	if sql.TableExists("evolve_info") then
		Msg("Evolve Info Exists!")
		evolve.PlayerInfo = {}
	else
		if (!sql.TableExists("evolve_info")) then
			query = "CREATE TABLE evolve_info ( unique_id varchar(255), nick text, rank text, steamid text, ip text, lastonline real, playtime real, banned integer)"
			result = sql.Query(query)
			if (sql.TableExists("evolve_info")) then
				Msg("Succes! Evolve Info Created! \n")
			else
				Msg("Somthing went wrong with the evolve_info query ! \n")
				Msg( sql.LastError( result ) .. "\n" )
			end	
		end
	end
 
	if sql.TableExists("evolve_bans") then
	Msg("Evolve Ban Table Exists!")
	else
		query = "CREATE TABLE evolve_bans ( unique_id varchar(255), nick text, steamid text, banend real, banreason text, banadmin text)"
		result = sql.Query(query)
					if (sql.TableExists("evolve_bans")) then
				Msg("Succes! Evolve Bans Created! \n")
			else
				Msg("Somthing went wrong with the evolve_bans query ! \n")
				Msg( sql.LastError( result ) .. "\n" )
			end	
	end	
end

 
function evolve:new_player( ply )
 
		local uniqueIDZ = ply:UniqueID()
		local Queryed = "INSERT INTO evolve_info VALUES ('"..uniqueIDZ.."', '"..ply:Nick().."', 'guest', '"..ply:SteamID().."', '"..ply:IPAddress().."', "..os.time()..", 0, 0)"
		sql.Query( Queryed )                    					
		result = sql.Query( "SELECT * FROM evolve_info WHERE unique_id = '"..uniqueIDZ.."'" )
		if (result) then
				Msg("Player account created !\n")
			else
				Msg("Something went wrong with creating Evolve Info for a Player !\n")
			end
 
end
 
function evolve:player_exists( ply )
 	uniqueID = ply:UniqueID()
	result = sql.Query( "SELECT * FROM evolve_info WHERE unique_id = '"..uniqueID.."'" )
	if (result) then
		Msg("Player account loaded!\n")
	else
		evolve:new_player( ply ) // Create a new player :D
	end
end
 
function SQLInitialize()
	evolve:tables_exist()
end
 
function SQLPlayerInitialSpawn( ply )
 
	timer.Create("Steam_id_delay", 1, 1, function()
		evolve:player_exists( ply ) 
	end)
 
end
 
 
 
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn2",SQLPlayerInitialSpawn)
hook.Add( "Initialize", "Initialize2",SQLInitialize)
 